package com.start.workflow.act;

import com.alibaba.fastjson2.JSONObject;
import com.start.workflow.entity.StartActModelConfig;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.activiti.engine.repository.ProcessDefinition;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Data
public class StartProcDef<T extends StartProcTaskDef> {
    @Schema(name = "流程部署id")
    private String procDeployId;
    @Schema(name = "流程定义Id")
    private String procDefId;
    @Schema(name = "模型名称")
    private String procName;
    @Schema(name = "模型key")
    private String procDefKey;
    @Schema(name = "流程分组key")
    private String procCategoryKey;
    @Schema(name = "流程主配置")
    private Map<String, StartActModelConfig> procConfig;
    @Schema(name = "流程配置xml")
    private String bpmnXml;
    @Schema(name = "表单配置")
    private StartActModelConfig procFormConfig;
    @Schema(name = "动态表单配置")
    private JSONObject formModelOption;
    @Schema(name = "流程节点")
    private List<T> procTasks;

    private StartActModelConfig nextTaskConfig;

    public StartProcDef() {

    }

    public StartProcDef(ProcessDefinition procDef) {
        procDefId = procDef.getId();
        procDeployId = procDef.getDeploymentId();
        procName = procDef.getName();
        procDefKey = procDef.getKey();
        procCategoryKey = procDef.getCategory();
    }

    public void addTask(T taskDef) {
        if (procTasks == null) {
            procTasks = new ArrayList<>();
        }
        procTasks.add(taskDef);
    }
}
